package net.wanho.controller;


import net.wanho.po.Attribute;
import net.wanho.service.AttributeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import lombok.RequiredArgsConstructor;



import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 属性表 前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2025-09-25
 */
@Api(tags = "属性表接口")
@RestController
@RequestMapping("/attribute")
@RequiredArgsConstructor
public class AttributeController {

    private final AttributeService attributeService;

    @ApiOperation("属性表分页查询")
    @GetMapping("/list")
    public AjaxResult findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") int pageNum,
                              @ApiParam("页大小") @RequestParam(defaultValue = "5") int pageSize,
                              @ApiParam("查询条件") Attribute attribute){
        PageInfo<Attribute> pageInfo = attributeService.findPage(pageNum,pageSize,attribute);
        return AjaxResult.success(pageInfo);
    }

    @ApiOperation("根据主键查询属性表")
    @GetMapping("/{attrId}")
    public AjaxResult findById(@PathVariable Serializable attrId){
        return AjaxResult.success(attributeService.findById(attrId));
    }

    @ApiOperation("新增属性表")
    @PostMapping
    public AjaxResult add(@RequestBody Attribute attribute){
        attributeService.add(attribute);
        return AjaxResult.success();
    }

    @ApiOperation("修改属性表")
    @PutMapping
    public AjaxResult modify(@RequestBody Attribute attribute){
        attributeService.modify(attribute);
        return AjaxResult.success();
    }

    @ApiOperation("根据主键删除属性表")
    @DeleteMapping("/{attrId}")
    public AjaxResult removeById(@PathVariable Serializable attrId){
        attributeService.removeById(attrId);
        return AjaxResult.success();
    }

}
